Repository navigation
fix(mcpx): refuse bare action PRAGMAs in the read-only log-sql guard (#6638) - #6700
Conversation
…6638) CheckReadOnly admitted any bare PRAGMA, so PRAGMA optimize, PRAGMA wal_checkpoint, PRAGMA incremental_vacuum and PRAGMA shrink_memory executed on the writable store through the read-only mcpx log sql surface. Bare PRAGMAs now pass only from an explicit allowlist of known reads (schema qualifier stripped, as in the function-form branch); unknown names are refused by default. incremental_vacuum disposition: refused - its bare form performs vacuum work. Regression coverage at guard level and RunSQL level, following TestRunSQLRefusesPragmaAssignments.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 44 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39e4841082
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for _, q := range []string{ | ||
| `PRAGMA optimize`, | ||
| `PRAGMA wal_checkpoint`, | ||
| `PRAGMA incremental_vacuum`, | ||
| `PRAGMA shrink_memory`, |
There was a problem hiding this comment.
Add a registry-driven guard for bare PRAGMA classification
The new regression coverage checks a fixed list of action names, but no test enumerates the new bareReadPragmas registry or SQLite's PRAGMA inventory. Consequently, classification changes outside these examples can go untested, contrary to the source testing rule requiring a registry-driven guard for class-wide fixes. Add table-driven coverage of the read registry and an independent action/refusal oracle, including schema-qualified and assignment permutations; retain these examples as regression cases.
AGENTS.md reference: pkgs/mcpx/internal/AGENTS.md:L11-L12
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c44c1a6. Added a registry-driven class guard in pkgs/mcpx/internal/logstore/sql_internal_test.go (internal test package, per the existing pattern in this directory):
TestBareReadPragmaRegistryGuarditeratesbareReadPragmasitself: every registered read must passCheckReadOnlybare, schema-qualified (main.<name>), and upper-case, and its assignment form (<name>=1) must be refused — as must its call form, except for the established function-form reads whose argument names an object.TestBareActionPragmasStayRefusedis the independent oracle: the action names (optimize,wal_checkpoint,incremental_vacuum,shrink_memory) are hardcoded from SQLite's PRAGMA inventory, not derived from the registry, and each must be absent from the allowlist and refused bare, schema-qualified, upper-case, and in call form.
The example-based cases in logstore_test.go are retained as regression cases. Verified: go test ./internal/logstore -count=1 pass; the guard set also passes -race -shuffle=on -count=5.
| "short_column_names": true, "soft_heap_limit": true, | ||
| "synchronous": true, "table_list": true, "temp_store": true, |
There was a problem hiding this comment.
Preserve the read_uncommitted setting query in the allowlist
For users inspecting the connection's isolation setting, mcpx log sql 'PRAGMA read_uncommitted' now fails because read_uncommitted is absent from this allowlist. This previously accepted statement is a genuine setting read: SQLite documents the bare query separately from its assignment form. Include it among the known reads while continuing to reject its value-carrying forms, so blocking action PRAGMAs does not also remove this read-only diagnostic.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c44c1a6. read_uncommitted is added to bareReadPragmas — the bare setting query passes again, while PRAGMA read_uncommitted=ON and PRAGMA read_uncommitted(1) remain refused by the value-form branches. PRAGMA read_uncommitted is also retained as a guard-level regression example in TestReadOnlyGuardRejectsAnythingThatWrites, and the new registry guard in sql_internal_test.go covers its permutations. Verified: go test ./internal/logstore -count=1 pass.
…read + registry guard (#6638) P2: PRAGMA read_uncommitted bare is a genuine setting read; added to bareReadPragmas (value forms still refused), with PRAGMA read_uncommitted retained as a guard-level regression example. P1: registry-driven class guard per pkgs/mcpx/internal/AGENTS.md — new sql_internal_test.go iterates bareReadPragmas asserting every registered read passes bare/schema-qualified/upper-case and its assignment (and, for bare-only reads, call) forms are refused; an independent hardcoded action oracle (optimize, wal_checkpoint, incremental_vacuum, shrink_memory) asserts those names stay out of the allowlist and refused in every form.
Fixes #6638.
Problem
CheckReadOnly(the guard for the read-onlymcpx log sqlsurface) refused value-carrying PRAGMAs after #3516, butcheckReadOnlyPragmapassed any bare PRAGMA — and SQLite has bare, no-value PRAGMAs that act instead of answering:PRAGMA optimize(rewritessqlite_stat1),PRAGMA wal_checkpoint(forces WAL frames into the main database file — this store's DSN is WAL mode),PRAGMA incremental_vacuum,PRAGMA shrink_memory. All executed on the writable store connection.Change
bareReadPragmas:journal_mode,user_version,schema_version,database_list,compile_options,integrity_check, current-setting reads, …). Unknown names are refused by default, so the next action PRAGMA is kept out by construction..— the same treatment as the function-form branch — soPRAGMA main.wal_checkpointcannot smuggle an action name past the allowlist (per Lane A's triage design note on mcpx(logstore): read-only log-sql guard still executes bare mutating PRAGMAs (optimize, wal_checkpoint) #6638).incremental_vacuumdisposition: refused — its bare form performs vacuum work (freelist 200 → 199 in rollback-journal mode); it is deliberately absent from the allowlist and named in the tests.Tests
TestReadOnlyGuardRejectsAnythingThatWrites):optimize,wal_checkpoint,incremental_vacuum,shrink_memory,main.optimize,main.wal_checkpoint;, and an unknown pragma added to the refused list;schema_version,database_list,compile_options,main.journal_mode,integrity_checkadded to the allowed list.TestRunSQLRefusesBareActionPragmas, followingTestRunSQLRefusesPragmaAssignments): the four action PRAGMAs plusmain.wal_checkpointare refused throughRunSQL;PRAGMA journal_modestill runs and returnswal.go test ./internal/logstore/— pass (incl. the three guard tests verbosely);go vet ./internal/logstore/clean;gofmtclean.pkgs/mcpxsuite: two failures ininternal/api(TestPluginOpsAreGenerated— staleops.gen.ts;TestTargetBearerTokenResolvesTheTargetDaemon— env-dependent).TestPluginOpsAreGeneratedreproduced identically on cleanorigin/mainwith this change stashed — pre-existing and unrelated to logstore.Propagation
mcpx also ships in
dezren39/darwin-nix, but that repo carries no logstore Go source (config/planning only — verified by grep this shift), so there is no nix-side copy of the guard to patch; this PR is the whole set for #6638.Filed and worked in queue fallback mode (queue backend down, code#6619) by Lane W.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.